package com.example.tests;

import com.example.framework.ContactData;
import com.example.utils.SortedListOf;
import org.testng.annotations.Test;

import java.util.Random;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

public class ContactRemovingTest extends TestManager {
    Random rnd = new Random();

    @Test
    public void shouldRemoveContact(){
        // save old state
        SortedListOf<ContactData> oldContactList =  new SortedListOf<ContactData>(manager.getHibernateHelper().listContacts());

        // actions
        int index = rnd.nextInt(oldContactList.size() - 1);
        manager.getContactHelper().deleteContactByIndex(index);

        // save new state
        SortedListOf<ContactData> newContactList = manager.getContactHelper().getAllContacts();

        // compare states
        assertThat(newContactList, equalTo(oldContactList.without(index)));
    }
}
